package com.jk.kdd.system.service;

import com.jk.kdd.system.dao.SystemUserRoleMapper;
import com.jk.kdd.system.model.SystemUserRole;
import com.jk.kdd.system.vo.SystemUserRoleVO;
import com.jk.util.BaseDataUtil;
import org.smart4j.framework.helper.BeanHelper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;


/**
 * Created by DELL on 2016/10/9.
 */
@Service
public class SystemUserRoleServiceImpl implements  SystemUserRoleService{

    @Resource
    private SystemUserRoleMapper systemUserRoleMapper;

    /**
     * 获取实体列表
     */
    public List<SystemUserRoleVO> getSystemUserRoleList() {
        return null;
    }
    /**
     * 根据主键获取实体
     */
    public SystemUserRoleVO getSystemUserRoleByPK(SystemUserRole user) {
        SystemUserRole systemUserRole = systemUserRoleMapper.selectByPrimaryKey(user.getId());
        SystemUserRoleVO systemUserRoleVO = new SystemUserRoleVO();
        BeanHelper.copyBean(systemUserRole,systemUserRoleVO);
        return systemUserRoleVO;
    }

    /**
     * 创建实体
     */
    @Transactional
    public boolean createSystemUserRole(SystemUserRole user, String operatorID) {
        // 创建角色
        BaseDataUtil.setBaseDataForEntity(user,"1",operatorID);
        systemUserRoleMapper.insertSelective(user);
        return true;
    }

    /**
     * 更新实体
     */
    @Transactional
    public boolean modifySystemUserRole(SystemUserRole user, String operatorID) {
        // 更新角色
        BaseDataUtil.setBaseDataForEntity(user,"2",operatorID);
        systemUserRoleMapper.updateByPrimaryKeySelective(user);
        return true;
    }

    /**
     * 删除实体
     */
    @Transactional
    public boolean removeSystemUserRole(SystemUserRole user, String operatorID) {
        // 删除角色
        BaseDataUtil.setBaseDataForEntity(user,"3",operatorID);
        systemUserRoleMapper.updateByPrimaryKeySelective(user);
        return true;
    }

}
